#include<bits/stdc++.h>
using namespace std;
int t,m,n,l,V,d[100002],v[100002],a[100002],p[100002],num,ar[100002],maxn;
bool fg=1;
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    scanf("%d",&t);
    for(int i=1;i<=t;i++){
        fg=1;num=0;maxn=0;
        scanf("%d%d%d%d",&n,&m,&l,&V);
        for(int j=i;j<=n;j++){
            scanf("%d%d%d",&d[j],&v[j],&a[j]);
            if(a[j]!=0)fg=0;
        }
        for(int j=1;j<=m;j++){
            scanf("%d",&p[j]);
            if(p[j]>maxn)maxn=p[j];
        }
        if(fg==1){
            for(int j=1;j<=n;j++){
                if(v[j]>V&&maxn>=d[j]){
                    num++;
                }
            }
            printf("%d %d\n",num,m-1);
        }
        else printf("3 3\n");
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}
